#!/bin/bash

# 监控服务管理脚本
# 用法: ./monitor_service.sh [start|stop|restart|status]

# 远程服务器信息
SERVER="root@182.160.6.140"
DEPLOY_PATH="/var/www/binance-analysis"

# 检查参数
if [ $# -lt 1 ]; then
  echo "用法: $0 [start|stop|restart|status]"
  exit 1
fi

ACTION=$1

case $ACTION in
  start)
    echo "启动监控服务..."
    ssh $SERVER "cd $DEPLOY_PATH && pm2 start scripts/monitor.js --name monitor-app && pm2 save"
    ;;
  stop)
    echo "停止监控服务..."
    ssh $SERVER "pm2 stop monitor-app && pm2 save"
    ;;
  restart)
    echo "重启监控服务..."
    ssh $SERVER "pm2 restart monitor-app && pm2 save"
    ;;
  status)
    echo "监控服务状态:"
    ssh $SERVER "pm2 show monitor-app"
    ;;
  *)
    echo "未知操作: $ACTION"
    echo "用法: $0 [start|stop|restart|status]"
    exit 1
    ;;
esac

echo "操作完成！" 